package edu.hawaii.myisern.action;

import java.util.List;
import edu.hawaii.myisern.model.MyIsernChecker;
import edu.hawaii.myisern.model.MyIsernModel;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;

/**
 * Provides a web interface for sanity report.
 * 
 * @author Edward Kim
 * @author JianFei Liao
 * @author KaYee Leung
 */
public class ReportActionBean implements ActionBean {

  /** Required by the ActionBean interface. */
  private ActionBeanContext context;
  /** An sigleton instance of the MyIsernModel. */
  private MyIsernModel myModel = MyIsernModel.getInstance();
  
  /** Invalid organizations links in researchers. */
  private List<String> invalidOrganizations;
  /** Invalid researchers links in organizations. */
  private List<String> invalidResearchers;
  /** Invalid collaborating organizations links in collaborations. */
  private List<String> invalidCollabOrganizations;

  
  /**
   * Returns the context. Required by the interface.
   * 
   * @return the ActionBeanContext.
   */
  public ActionBeanContext getContext() {
    return context;
  }

  /**
   * Sets the context. Required by the interface.
   * 
   * @param context The ActionBeanContext to set.
   */
  public void setContext(ActionBeanContext context) {
    this.context = context;
  }

  /**
   * Gets the list of invalid organizations for all the researchers.
   * 
   * @return A list of invalid organizations.
   */
  public List<String> getInvalidOrganizations() {
    MyIsernChecker checker = new MyIsernChecker(this.myModel);
    this.invalidOrganizations = checker.invalidOrganizationLinksForResearchers();
    return this.invalidOrganizations;
  }
  
  /**
   * Gets the list of invalid researchers for all the organizations.
   * 
   * @return A list of invalid researchers.
   */
  public List<String> getInvalidResearchers() {
    MyIsernChecker checker = new MyIsernChecker(this.myModel);
    this.invalidResearchers = checker.invalidResearchersLinksForOrganizations();
    return this.invalidResearchers;
  }
  
  /**
   * Gets the list of invalid collaborating organizations for all the collaborations.
   * 
   * @return A list of invalid collaborating organizations.
   */
  public List<String> getInvalidCollabOrganiztions() {
    MyIsernChecker checker = new MyIsernChecker(this.myModel);
    this.invalidCollabOrganizations = checker.invalidCollabOrganizationsLinksForCollaborations();
    return this.invalidCollabOrganizations;
  }
  
  /**
   * Shows a sanity report.
   * 
   * @return A Resolution indicating to redisplay report.jsp pagse.
   * @throws Exception error message
   */
  @DefaultHandler
  public Resolution showReport() throws Exception {
    return new RedirectResolution("/report.jsp").flash(this);
  }
}